package com.apop.demo.encrypt;

import com.apop.demo.encrypt.EncryptionStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 加密策略工厂
 * @Description:
 * @Author: zjy
 * @Date: 2025/2/26 15:21
 */
@Component
public class EncryptionStrategyFactory {

    private final Map<String, EncryptionStrategy> encryptionStrategies;

    @Autowired
    public EncryptionStrategyFactory(Map<String, EncryptionStrategy> encryptionStrategies) {
        this.encryptionStrategies = encryptionStrategies;
    }

    public EncryptionStrategy getEncryptionStrategy(String type) {
        if (encryptionStrategies.containsKey(type)) {
            return encryptionStrategies.get(type);
        } else {
            throw new IllegalArgumentException("不支持的类型: " + type);
        }
    }

    public EncryptionStrategy getEncryptionStrategy(EncryptTypeEnum encryptTypeEnum) {
        if (encryptionStrategies.containsKey(encryptTypeEnum.getType())) {
            return encryptionStrategies.get(encryptTypeEnum.getType());
        } else {
            throw new IllegalArgumentException("不支持的类型: " + encryptTypeEnum.getType());
        }
    }
}
